#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, m;
struct Node {
  int v, id;
  bool operator<(const Node& o) const { return v > o.v; }
} a1[N], a2[N];
int n1, n2;
int sum1[N], sum2[N];
void solve() {
  cin >> n >> m;
  rep(i, 1, n) {
    int x, y;
    cin >> x >> y;
    if (x == 1) a1[++n1] = {y, i};
    if (x == 2) a2[++n2] = {y, i};
  }
  sort(a1 + 1, a1 + n1 + 1);
  sort(a2 + 1, a2 + n2 + 1);
  rep(i, 1, n1) sum1[i] = sum1[i - 1] + a1[i].v;
  rep(i, 1, n2) sum2[i] = sum2[i - 1] + a2[i].v;
  if (n1 + n2 * 2 <= m) {
    cout << sum1[n1] + sum2[n2] << endl;
    rep(i, 1, n) cout << i << ' ';
    cout << endl;
  } else {
    int mx = 0, x1 = 0, x2 = 0;
    rep(i, 0, min(n1, m)) {
      int j = (m - i) / 2;
      if (mx < sum1[i] + sum2[j]) {
        x1 = i, x2 = j;
        mx = sum1[i] + sum2[j];
      }
    }
    cout << mx << endl;
    set<int> id;
    rep(i, 1, x1) id.insert(a1[i].id);
    rep(i, 1, x2) id.insert(a2[i].id);
    for (int x : id) cout << x << ' ';
    cout << endl;
  }
  return;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  t = 1;
  while (t--) solve();
  return 0;
}